#include "extent.h"
#include "xil_printf.h"
#include "memory_map.h"

void analyse_extent(char* addr){
	char* addr_index = addr;
	struct fiemap_extent* extents = (struct fiemap_extent*)EXTENTS;

	unsigned long long file_size;
	int num_extent;

	//copy data from dma buffer
	memcpy(&file_size,addr_index,sizeof(unsigned long long));
	addr_index += sizeof(unsigned long long);

	memcpy(&num_extent,addr_index,sizeof(unsigned long));
	addr_index += sizeof(unsigned long);

	memcpy(extents,addr_index,sizeof(struct fiemap_extent)*num_extent);

	unsigned long long fe_logical;
	unsigned long long fe_physical;
	unsigned long long fe_length;
	unsigned long fe_flags;

	//copy end
	printf("num_extent:%d\n\rfile size:%llu\n\r",num_extent,file_size);
	for(int i=0;i<num_extent;i++){
		fe_logical = extents[i].fe_logical;
		fe_physical = extents[i].fe_physical;
		fe_length = extents[i].fe_length;
		fe_flags = extents[i].fe_flags;

		xil_printf("%d th extent\n\r",i);
		printf("\tfe_logical : %llu\n\r",fe_logical);
		printf("\tfe_physical : %llu\n\r",fe_physical);
		printf("\tfe_length : %llu\n\r",fe_length);
		printf("\tfe_flags : %lu\n\r",fe_flags);
	}

	return;
}
